<%--                                                                       --%>
<%-- Copyright (c) 2001-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ page import = "com.broadvision.portal.foundation.action.microsite.participant.ParticipantBaseAction" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<%
  String delimiter = ParticipantBaseAction.DELIMITER;
%>

<script language="JavaScript">


// click cancel button goes to microsite list page
function confirmCancel(theForm) {
  if ( confirm('<bean:message key="cs.confirm.cancel.microsite"/>') ){
    theForm.action = '<c:url value="/cs/microsite/cancelWizard.do"/>';
    theForm.submit();
  } else {
    return false;
  }
}        


function clickBack(theForm) {
  <c:if test="${msNewForm.map.usePhase}">
    theForm.action = '<c:url value="/cs/microsite/phaseList.do"/>';
  </c:if>
  <c:if test="${!msNewForm.map.usePhase}">
    theForm.action = '<c:url value="/cs/microsite/msNewDetails.do"/>';
  </c:if>
  
  theForm.submit();
}

function confirmDelete(theForm) {
  if ( confirm('<bean:message key="cs.confirm.delete.participant"/>') ){
    return true;
  } else {
    return false;
  }
}        


//
// Create a dummy (timestamp) attribute to get around an IE cache problem.
//
function getTimeStamp() {
   var now = new Date;
   var timestamp = '' + now.getYear() + now.getMonth() + now.getDate() + now.getHours() + now.getMinutes() + now.getSeconds() + now.getMilliseconds();
   return timestamp;
}   

var win;

var popupURL = '<c:url value="/cs/msParticipantFind.do"/>';
function findUserPopup() {
  var timestamp = getTimeStamp();
  win = window.open(popupURL + '?timestamp=' + timestamp, "SelectParticipants" , "width=700,height=600,scrollbars=yes,resizable=yes");
  if ( win != null) {
    if( win.opener == null) {
      win.opener = self;
    }
  }
  win.focus(); 
}

var refreshURL = '<c:url value="/cs/microsite/participantAdd.do"/>';
function refreshParticipants(userList) {
  if ( userList.length <= 0 )
    return;

  var participantList = "" ;
  if ( refreshURL.indexOf("?") < 0 ) {
    participantList = '?newParticipants=' + userList;
  } else {
    participantList = '&newParticipants=' + userList;
  }
  window.location = refreshURL + participantList;
  if ( win != null ) {
    win.focus(); 
  }
}

var refreshGroupURL = '<html:rewrite page="/cs/microsite/participantGroupAdd.do"/>';

function refreshGroupParticipants(groupList) {
  if ( groupList.length <= 0 )
    return;

  var participantList = "" ;
  participantList = '?newParticipants=' + groupList.join("<%=delimiter%>");

  window.location = refreshGroupURL + participantList;
  if ( win != null ) {
    win.focus();
  }
}

var groupPopupURL = '<html:rewrite page="/cs/microsite/participantFindGroup.do"/>';
function findGroupPopup() {
  var timestamp = getTimeStamp();
  win = window.open(groupPopupURL + '?timestamp=' + timestamp, "SelectGroupParticipants" , "width=700,height=600,scrollbars=yes,resizable=yes");
  if ( win != null) {
    if( win.opener == null) {
      win.opener = self;
    }
  }
  win.focus();
}

function confirmDeleteGroup() {
  if ( confirm('<bean:message key="cs.confirm.delete.group.participant"/>') ){
    return true;
  } else {
    return false;
  }
}    

function validateForm(theForm) {
  //
  // check at least one participant is designated as a microsite owner.
  //
  var len = theForm.ownerIds.length;
  
  var valid = 0;
  if ( len > 1 ) {
    for ( var i=0; i<len; i++ ) {
      if ( theForm.ownerIds[i].checked == true ) {
        valid = 1;
        break;
      }
    }
  } else {
    if ( theForm.ownerIds.checked == true ) {
      valid = 1;;
    }
  }

  if ( valid == 0 ) {
    alert('<bean:message key="cs.error.one.participant.owner"/>');
    return;
  }

  theForm.submit();
}
</script>


<!-- Zone 5 starts here.  -->
<html:form action="/cs/microsite/participantUpdate.do">

<html:hidden name="msNewForm" property="templateId"/>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" 
         summary="wizard participant list">
  <tr>
    <td valign="top">
    
    <div class="pageTitle">
      <bean:message key="ep.wizard.pageTitle" 
                    arg0="${msNewForm.map.currentStep}"/><bean:message key="cs.participants"/>
    </div>
    <div class="app_pageSubtitle">
      <span class="left">
        <bean:message key="cs.participant.list.title"/>
      </span>
      <span class="right">
       <html:button styleClass="titleButton" property="popupBtn" onclick="findUserPopup()">
          <bean:message key="button.findMoreParticipants"/>
       </html:button>
      </span>
    </div>
    
		<div class="blockWrap">
		
    <!-- start Page Instructions -->
    <div class="pageInstructions">
      <bean:message key="cs.participant.note"/>
    </div>
    <!-- End Page Instructions -->
    

    <!--end title bar here-->

 
    <!-- Start List here -->
    <table class="dataTable" border="0" cellspacing="1" cellpadding="2" 
           summary="wizard participant list table" width="100%">
      <tr class="listHeader"> 
        <th id="Name" align="left" width="30%"><bean:message key="cs.name"/></th>
        <th id="Login" align="left" width="17%"><bean:message key="cs.login"/></th>
        <th id="Owner" align="center" width="15%"><bean:message key="cs.owner"/></th>
        <th id="Contact" align="center" width="15%"><bean:message key="cs.participant.contact"/></th>
        <th id="Action" align="left" width="23%"><bean:message key="cs.actions"/></th>
      </tr>

      <c:forEach var="oneParticipant" items="${msNewForm.map.participantList}" 
                 varStatus = "status" >
          <c:choose>
            <c:when test="${(status.count + 1) % 2 == 0}">
              <tr class="listOdd">
            </c:when> 
            <c:otherwise>
              <tr class="listEven">
            </c:otherwise>
          </c:choose> 
                 
          <td headers="Name" align="left" width="30%"> 
          	<c:out value="${oneParticipant.map.fullName}"/>
          </td>
          <td headers="Login" align="left" width="17%"> 
          	<c:out value="${oneParticipant.map.username}"/>
          </td>
          <td headers="Owner" align="center" width="15%">
            <html:multibox name="msNewForm" property="ownerIds" value="${oneParticipant.map.visitorId}"/>  
          </td>
          <td headers="Contact" align="center" width="15%"> 
            <html:multibox name="msNewForm" property="contactIds" value="${oneParticipant.map.visitorId}"/>
          </td>
          <%-- Microsite creator is always the first participant in the participatn list. --%> 
          <%-- We don't allow microsite creator to remove himself from the participant list. --%>
        
          <td headers="Action" align="left" width="23%">
          <c:if test="${ status.count != 1}" >
            <c:url var="deleteUrl" value="/cs/microsite/participantRemove.do">
              <c:param name="userId" value="${oneParticipant.map.visitorId}"/>
            </c:url>
            <a href='<c:out value="${deleteUrl}"/>' onclick="return confirmDelete();">
              <html:img page="/cs/images/action/icon_delete.gif" styleClass="actionIcon" 
                  altKey="cs.image.alt.delete" border="0"/>
            </a>
          </c:if>
          </td>
       </tr>
     </c:forEach>  
    </table>      
            
    <!-- End participants list -->

  <c:if test="${msNewForm.map.useLdap}">
	  </div> 
	  <div class="app_pageSubtitle">
        <span class="left">
          <bean:message key="cs.participant.group.list.title"/>
        </span>
        <span class="right">
          <html:button property="findGroup" onclick="findGroupPopup()" styleClass="titleButton">
            <bean:message key="cs.button.findMoreGroupParticipants"/>
          </html:button>
        </span>
      </div>
			
			<div class="blockWrap"> 
	  <!-- Start Groups List here -->
      <table class="dataTable" border="0" cellspacing="1" cellpadding="0" 
           summary="Group participant list table" width="100%">
        <tr class="listHeader"> 
          <th id="FullName" align="left"><bean:message key="cs.name"/></th>
          <th id="Action" align="left"><bean:message key="cs.actions"/></th>
        </tr>
        <c:forEach var="oneGroup" items="${msNewForm.map.groupParticipantList}" varStatus="status">
          <c:choose>
            <c:when test="${(status.index) % 2 == 0}">
              <tr class="listEven">
            </c:when> 
            <c:otherwise>
              <tr class="listOdd">
            </c:otherwise>
          </c:choose> 
            <td headers="FullName" align="left">
              <c:out value="${oneGroup.map.fullName}" />
            </td>
            <td headers="Action" align="left">&nbsp;
              <%-- Display delete button --%>
              <html:link page="/cs/microsite/participantGroupDelete.do" paramId="groupName" paramName="oneGroup" paramProperty="fullName" onclick="return confirmDeleteGroup();">
                <html:img page="/cs/images/action/icon_remove.gif" styleClass="actionIcon" border="0" altKey="cs.image.alt.remove"/>
              </html:link>
            </td>
          </tr> 
        </c:forEach>
      </table>
    </c:if>
    
        <!--start cancel, reset, save bar area here-->
        <div class="pageButtonWrap" align="right">
          <html:button styleClass="pageButton" property="cancelBtn" titleKey="button.cancel" 
                       onclick='return confirmCancel(this.form)'>
            <bean:message key="button.cancel"/>
          </html:button>
          
                       
          <html:button styleClass="pageButton" property="backBtn" titleKey="button.back" onclick="clickBack(this.form)">
            <bean:message key="button.back"/>
          </html:button>
          
          <html:button styleClass="pageButton" property="nextBtn" 
                       titleKey="button.next"
                       onclick='return validateForm(this.form);'>
              <bean:message key="button.next"/>
          </html:button>
    
        </div>
			</div> <!--end blockWrap-->	         
       
    </td>
  </tr>
</table>

</html:form>  

